
import md5 from 'js-md5'
import moment from 'moment'
 import { uploads } from "@/api/common_api"; 

export function parseTime(time, cFormat) {
  if (arguments.length === 0 || !time) {
    return null
  }
  const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
  let date
  if (typeof time === 'object') {
    date = time
  } else {
    if ((typeof time === 'string')) {
      if ((/^[0-9]+$/.test(time))) {
        time = parseInt(time)
      } else {
        time = time.replace(new RegExp(/-/gm), '/')
      }
    }

    if ((typeof time === 'number') && (time.toString().length === 10)) {
      time = time * 1000
    }
    date = new Date(time)
  }
  const formatObj = {
    y: date.getFullYear(),
    m: date.getMonth() + 1,
    d: date.getDate(),
    h: date.getHours(),
    i: date.getMinutes(),
    s: date.getSeconds(),
    a: date.getDay()
  }
  const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
    const value = formatObj[key]
    // Note: getDay() returns 0 on Sunday
    if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] }
    return value.toString().padStart(2, '0')
  })
  return time_str
}

//转时间格式
export function formatDate(date, cFormat) {
  if (date == '' || date == undefined) {
    return ''
  }
  if(cFormat){  
    return moment(date).format("YYYY-MM-DD")
  }else{
    return moment(date).format("YYYY-MM-DD  HH:mm:ss")
  }
}

export function formatTime(time, option) {
  if (('' + time).length === 10) {
    time = parseInt(time) * 1000
  } else {
    time = +time
  }
  const d = new Date(time)
  const now = Date.now()

  const diff = (now - d) / 1000

  if (diff < 30) {
    return '刚刚'
  } else if (diff < 3600) {
    // less 1 hour
    return Math.ceil(diff / 60) + '分钟前'
  } else if (diff < 3600 * 24) {
    return Math.ceil(diff / 3600) + '小时前'
  } else if (diff < 3600 * 24 * 2) {
    return '1天前'
  }
  if (option) {
    return parseTime(time, option)
  } else {
    return (
      d.getMonth() +
      1 +
      '月' +
      d.getDate() +
      '日' +
      d.getHours() +
      '时' +
      d.getMinutes() +
      '分'
    )
  }
}

/**
 * @param {string} url
 * @returns {Object}
 */
export function param2Obj(url) {
  const search = decodeURIComponent(url.split('?')[1]).replace(/\+/g, ' ')
  if (!search) {
    return {}
  }
  const obj = {}
  const searchArr = search.split('&')
  searchArr.forEach(v => {
    const index = v.indexOf('=')
    if (index !== -1) {
      const name = v.substring(0, index)
      const val = v.substring(index + 1, v.length)
      obj[name] = val
    }
  })
  return obj
}

//解析结构
export function arrayFormat(arr) {
  let newArray = [];
  arr.forEach((v)=>{
    let str = {};
    str.label = v.name;
    str.value = v.id;
    newArray.push(str);
  })
  return newArray;
}

// md5加密
export function loginMD5(passworld) {
  return md5(passworld)
}

/**
 * 数组去重
 * @param {*} arr 接收的原数组
 * @param {*} key 如果是对象数组[{id: 1}, {id: 2}, {id: 3}]，则需要以什么key作为重复的标准，普通数组[1,2,3,2]不需要
 */
export function arrUnique(arr, key) {
  let returnArr = [];
  if (key) {
      // 对象数组去重
      const obj = {};
      returnArr = arr.reduce((cur, next) => {
          obj[next[key]] ? '' : obj[next[key]] = true && cur.push(next);
          return cur;
      }, []);
      return returnArr;
  }
  // 普通数组去重
  const obj = {};
  returnArr = arr.reduce((cur, next) => {
      !cur.includes(next) && cur.push(next);
      return cur;
  }, []);
  return returnArr;
}

//-----------------------------------------------------------






export function timeFix() {
  const time = new Date()
  const hour = time.getHours()
  return hour < 9 ? '早上好' : hour <= 11 ? '上午好' : hour <= 13 ? '中午好' : hour < 20 ? '下午好' : '晚上好'
}

export function welcome () {
  const arr = ['休息一会儿吧', '想想待办的事情?', '有什么需要帮助的呢', '我猜你可能累了']
  const index = Math.floor(Math.random() * arr.length)
  return arr[index]
}

/**
 * 当前日期
 */
export function getNowDate () {
    let date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    if (month <= 9) {
        month = '0' + month
    }
    var strDate = date.getDate(),seperator1 = '-';
    if (strDate <= 9) strDate = '0' + strDate
    let time = year + seperator1 + month + seperator1 + strDate;
    return time;
}

export function getCurrentTime() {
  let yy = new Date().getFullYear();
  let mm = new Date().getMonth()+1;
  if (mm < 10) {
    mm = "0" + mm;
  }
  let dd =
    new Date().getDate() < 10
      ? "0" + new Date().getDate()
      : new Date().getDate();
  let hh =
    new Date().getHours() < 10
      ? "0" + new Date().getHours()
      : new Date().getHours();
  let mf = new Date().getMinutes()<10 ? '0'+new Date().getMinutes() : new Date().getMinutes();
  let ss = new Date().getSeconds()<10 ? '0'+new Date().getSeconds() : new Date().getSeconds();
  let time = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss;
  return time;
}

export function getRecentDay(n) {
  let day = moment(new Date()).subtract(n, 'days').format('YYYY-MM-DD');
  return day;
}

/**
 * 
 * @returns RandomSixStr
 */
export function getRandomSixNum() {
    let RandomSixStr = ''
    for(let i = 0;i < 6; i++) {
        RandomSixStr += String(Math.floor(Math.random()*10))
    }
    return RandomSixStr
}
export function createGSCanvas(img) {
    var canvas = document.createElement("canvas");
    canvas.width = img.width;
    canvas.height = img.height;
  var ctx = canvas.getContext("2d");
    ctx.drawImage(img, 0, 0);
  var c = ctx.getImageData(0, 0, img.width, img.height);

  var pixeldata = c.data;
  for (var i = 0, len = pixeldata.length; i < len; i += 4){
    if (c.data[i + 3] === 0) {
      c.data[i] = 255;
      c.data[i + 1] = 255;
      c.data[i + 2] = 255;
      c.data[i + 3] = 255;
    }
    var black =( c.data[i] + c.data[i+1] + c.data[i+2])/3;
    if(black>=100){
        black = i
    }else{
        black = 0;
    }
    c.data[i] = black;
    c.data[i+1] = black;
    c.data[i+2] = black;
  }

   /*  for(var i = 0; i < img.width; i++){
        for(var j = 0; j < img.height; j++){
            var x = (j* 4) * c.width + (i * 4);
          var r = 0;
          var g = 0;
          var b = 0;
            c.data[x] = c.data[x+1] = c.data[x+2] = (r+g+b)/3;
        }
    } */
    ctx.putImageData(c,0,0,0,0,c.width,c.height); 
    
      return canvas.toDataURL();
}

/*随机数*/
export function generateMixed(n) {
  var res = "";
  var chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
    for(var i = 0; i < n ; i ++) {
        var id = Math.ceil(Math.random()*35);
        res += chars[id];
    }
    return res;
}

// 数据合并
export function mergeRecursive(source, target) {
  for (var p in target) {
    try {
      if (target[p].constructor == Object) {
        source[p] = mergeRecursive(source[p], target[p]);
      } else {
        source[p] = target[p];
      }
    } catch (e) {
      source[p] = target[p];
    }
  }
  return source;
};

/**
 * 触发 window.resize
 */
export function triggerWindowResizeEvent () {
  const event = document.createEvent('HTMLEvents')
  event.initEvent('resize', true, true)
  event.eventType = 'message'
  window.dispatchEvent(event)
}

export function handleScrollHeader (callback) {
  let timer = 0

  let beforeScrollTop = window.pageYOffset
  callback = callback || function () {}
  window.addEventListener(
    'scroll',
    event => {
      clearTimeout(timer)
      timer = setTimeout(() => {
        let direction = 'up'
        const afterScrollTop = window.pageYOffset
        const delta = afterScrollTop - beforeScrollTop
        if (delta === 0) {
          return false
        }
        direction = delta > 0 ? 'down' : 'up'
        callback(direction)
        beforeScrollTop = afterScrollTop
      }, 50)
    },
    false
  )
}

export function isIE () {
  const bw = window.navigator.userAgent
  const compare = (s) => bw.indexOf(s) >= 0
  const ie11 = (() => 'ActiveXObject' in window)()
  return compare('MSIE') || ie11
}

//获取当前日期函数
export function getNowFormatDate() {
  let date = new Date(),
    seperator1 = '-', //格式分隔符
    year = date.getFullYear(), //获取完整的年份(4位)
    month = date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
    strDate = date.getDate() // 获取当前日(1-31)
  if (month >= 1 && month <= 9) month = '0' + month // 如果月份是个位数，在前面补0
  if (strDate >= 0 && strDate <= 9) strDate = '0' + strDate // 如果日是个位数，在前面补0
 
  let currentdate = year + seperator1 + month + seperator1 + strDate 
  return currentdate
}

export function monthDay(year, month) {
    var seperator1 = '-';
    var date = new Date(year, month, 1)
    var yesterDay = new Date(date - 1000)
    return year + seperator1 + month + seperator1 + yesterDay.getDate()
}

/**
 * Remove loading animate
 * @param id parent element id or class
 * @param timeout
 */
export function removeLoadingAnimate (id = '', timeout = 1500) {
  if (id === '') {
    return
  }
  setTimeout(() => {
    document.body.removeChild(document.getElementById(id))
  }, timeout)
}

export function checkAmount(val) {
    if (!(/^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$/.test(val))) {
        return false;
    }
    return true;
}

//验证数字+字母
export function validateAccount(value) {
   var pwdblank = /^\S*$/;
   var pattern = new RegExp(
     "[`~!@#$^&*()=|{}':;',\\[\\].<>《》/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]"
   );
   var regUpper = /[A-Z]/;
   var regLower = /[a-z]/;
   var regStr = /[0-9]/;
   var complex = 0;
   if (regLower.test(value)) {
     ++complex;
   }
   if (regUpper.test(value)) {
     ++complex;
   }
   if (regStr.test(value)) {
     ++complex;
   }
  if (!pwdblank.test(value)) {
     return 1
  } else if (pattern.test(value)) {
    return 2
  } else if (complex < 2) {
    return 3
  } 
  return 4
       }

//密码校验
export function checkPwd(val) {
  const regex = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%~#^*?&])[A-Za-z\d$@$!%~#^*?&]{8,}$/; // /^(?=.*[a-zA-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
  if (regex.test(val)) {
    return true;
  }
  return false;
}

//银行卡正则校验
export function checkBankno(bankno) {
  var lastNum = bankno.substr(bankno.length - 1, 1); //取出最后一位（与luhm进行比较）
  var first15Num = bankno.substr(0, bankno.length - 1); //前15或18位
  var newArr = [];

  for (var i = first15Num.length - 1; i > -1; i--) { //前15或18位倒序存进数组
    newArr.push(first15Num.substr(i, 1));
  }

  var arrJiShu = []; //奇数位*2的积 <9
  var arrJiShu2 = []; //奇数位*2的积 >9
  var arrOuShu = []; //偶数位数组
  for (var j = 0; j < newArr.length; j++) {
    if ((j + 1) % 2 == 1) { //奇数位
      if (parseInt(newArr[j]) * 2 < 9)
        arrJiShu.push(parseInt(newArr[j]) * 2);
      else
        arrJiShu2.push(parseInt(newArr[j]) * 2);
    } else //偶数位
      arrOuShu.push(newArr[j]);
  }

  var jishu_child1 = []; //奇数位*2 >9 的分割之后的数组个位数
  var jishu_child2 = []; //奇数位*2 >9 的分割之后的数组十位数
  for (var h = 0; h < arrJiShu2.length; h++) {
    jishu_child1.push(parseInt(arrJiShu2[h]) % 10);
    jishu_child2.push(parseInt(arrJiShu2[h]) / 10);
  }

  var sumJiShu = 0; //奇数位*2 < 9 的数组之和
  var sumOuShu = 0; //偶数位数组之和
  var sumJiShuChild1 = 0; //奇数位*2 >9 的分割之后的数组个位数之和
  var sumJiShuChild2 = 0; //奇数位*2 >9 的分割之后的数组十位数之和
  var sumTotal = 0;
  for (var m = 0; m < arrJiShu.length; m++) {
    sumJiShu = sumJiShu + parseInt(arrJiShu[m]);
  }
  for (var n = 0; n < arrOuShu.length; n++) {
    sumOuShu = sumOuShu + parseInt(arrOuShu[n]);
  }
  for (var p = 0; p < jishu_child1.length; p++) {
    sumJiShuChild1 = sumJiShuChild1 + parseInt(jishu_child1[p]);
    sumJiShuChild2 = sumJiShuChild2 + parseInt(jishu_child2[p]);
  }
  //计算总和
  sumTotal = parseInt(sumJiShu) + parseInt(sumOuShu) + parseInt(sumJiShuChild1) + parseInt(sumJiShuChild2);
  //计算Luhm值
  var k = parseInt(sumTotal) % 10 == 0 ? 10 : parseInt(sumTotal) % 10;
  var luhm = 10 - k;
  if (lastNum == luhm) {
    return true;
  } else {
    return false;
  }
}


//身份证
export function checkIDCard(idcode){
  // 加权因子
  var weight_factor = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2];
  // 校验码
  var check_code = ['1', '0', 'X' , '9', '8', '7', '6', '5', '4', '3', '2'];
  var code = idcode + "";
  var last = idcode[17];//最后一个
  var seventeen = code.substring(0,17);
  // ISO 7064:1983.MOD 11-2
  // 判断最后一位校验码是否正确
  var arr = seventeen.split("");
  var len = arr.length;
  var num = 0;
  for(var i = 0; i < len; i++){
      num = num + arr[i] * weight_factor[i];
  }
  // 获取余数
  var resisue = num%11;
  var last_no = check_code[resisue];
  // 格式的正则
  // 正则思路
  /*
  第一位不可能是0
  第二位到第六位可以是0-9
  第七位到第十位是年份，所以七八位为19或者20
  十一位和十二位是月份，这两位是01-12之间的数值
  十三位和十四位是日期，是从01-31之间的数值
  十五，十六，十七都是数字0-9
  十八位可能是数字0-9，也可能是X
  */
  var idcard_patter = /^[1-9][0-9]{5}([1][9][0-9]{2}|[2][0][0|1][0-9])([0][1-9]|[1][0|1|2])([0][1-9]|[1|2][0-9]|[3][0|1])[0-9]{3}([0-9]|[X])$/;
 
  // 判断格式是否正确
  var format = idcard_patter.test(idcode);
 
  // 返回验证结果，校验码和格式同时正确才算是合法的身份证号码
  return last === last_no && format ? true : false;
}

//信用统一代码
export function CheckSocialCreditCode(Code) { 
	var patrn = /^[0-9A-Z]+$/;  
	//18位校验及大写校验  
	if ((Code.length != 18) || (patrn.test(Code) == false)) {  
		return false;  
	} else {  
		var Ancode;//统一社会信用代码的每一个值  
		var Ancodevalue;//统一社会信用代码每一个值的权重   
		var total = 0;  
		var weightedfactors = [1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28];//加权因子   
		var str = '0123456789ABCDEFGHJKLMNPQRTUWXY';  
		//不用I、O、S、V、Z   
		for (var i = 0; i < Code.length - 1; i++) {  
			Ancode = Code.substring(i, i + 1);  
			Ancodevalue = str.indexOf(Ancode);  
			total = total + Ancodevalue * weightedfactors[i];  
			//权重与加权因子相乘之和   
	    }  
		var logiccheckcode = 31 - total % 31;  
		if (logiccheckcode == 31) {  
			logiccheckcode = 0;  
        }  
		var Str = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,T,U,W,X,Y";  
		var Array_Str = Str.split(',');  
		logiccheckcode = Array_Str[logiccheckcode]; 
		var checkcode = Code.substring(17, 18);  
		if (logiccheckcode != checkcode) {  
			return false;  
		}
		return true;  
	}  
}

/**
 * 手机号验证
 * @param {*} val  
 * @returns 
 */
export function checkPhone(val) {
  if (!(/^1(3[0-9]|4[0-9]|5[0-9]|6[0-9]|7[0-9]|8[0-9]|9[0-9])\d{8}$/.test(val))) {
    return false;
  }
  return true;
}

/**
 * 座机兼顾手机
 * @param {*} val 
 * @returns 
 */
export function checkPhoneOrLandline(val) {
    if (!/^(((\d{3,4}-)?[0-9]{7,8})|(1(3|4|5|6|7|8|9)\d{9}))$/.test(val)) {
        return false;
    }
    return true;
}


export function checkEmail(value) {
  if (!/^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/.test(value)) {
    return false
  }
  return true;
}

/**
 * 数字
 * @param {*} val 
 * @returns 
 */
export function checkNumber(val) {
    if (!/^[0-9,]*$/.test(val)) {
        return false;
    }
    return true;
}

/**
 * 验证是否是中文
 * @param {*} val 
 * @returns 
 */
export function checkChinese(val) {
    var pattern = new RegExp("[\u4E00-\u9FA5]+");
    if(!pattern.test(val)){
        return false;
    }
    return true;
}

/**
 * 验证是否是英文
 * @param {*} val 
 * @returns 
 */
export function checkEnglish(val) {
    var pattern = new RegExp("[A-Za-z]+");
    if(!pattern.test(val)){
        return false;
    }
    return true;
}
 



/**
 *  预览文件
 */
export function previewFile(files) {
  if (!files) { return; }
  window.open(files,"_blank");
 /*  var form = document.createElement('form');
  form.action = files;
  form.target = '_blank';
  form.method = 'get';
  document.body.appendChild(form);
  form.submit(); */
}

export function downExecl(response,name) {
    let link = document.createElement('a');
    var blob = new Blob([response],{ type: 'application/vnd.ms-excel'});
    link.download = name;
    link.style.display = 'none'
    link.href = URL.createObjectURL(blob);
    document.body.appendChild(link)
    link.click()
    document.body.removeChild(link)
}

export function downtcv(response) {
    const link = document.createElement("a");
    let blob = new Blob([response]);
    link.style.display = "none";
    link.href = URL.createObjectURL(blob);
    document.body.appendChild(link);
    link.click();
}

 
/**
 * 小写金额转成大写金额
 * @param {number} money
 * @returns
 */
export function convertLowercaseAmountsToUppercase(money) {
  // 汉字的数字
  const cnNums = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
  // 基本单位
  const cnIntRadice = ['', '拾', '佰', '仟']
  // 对应整数部分扩展单位
  const cnIntUnits = ['', '万', '亿', '兆']
  // 对应小数部分单位
  const cnDecUnits = ['角', '分', '厘', '毫', '丝']
  // 整数金额时后面跟的字符
  const cnInteger = '整'
  // 整型完以后的单位
  const cnIntLast = '元'
  // 最大处理的数字
  const maxNum = 9999999999999999.99
  // 金额整数部分
  let integerNum
  // 金额小数部分
  let decimalNum
  // 输出的中文金额字符串
  let chineseStr = ''
  // 分离金额后用的数组，预定义
  let parts
  if (money === '') {
    return ''
  }
  money = parseFloat(money)
  if (money >= maxNum) {
    // 超出最大处理数字
    return ''
  }
  if (money === 0) {
    chineseStr = cnNums[0] + cnIntLast + cnInteger
    return chineseStr
  }
  // 转换为字符串
  money = money.toString()
  if (money.indexOf('.') === -1) {
    integerNum = money
    decimalNum = ''
  } else {
    parts = money.split('.')
    integerNum = parts[0]
    decimalNum = parts[1].substr(0, 4)
  }
  // 获取整型部分转换
  if (parseInt(integerNum, 10) > 0) {
    let zeroCount = 0
    const IntLen = integerNum.length
    for (let i = 0; i < IntLen; i++) {
      const n = integerNum.substr(i, 1)
      const p = IntLen - i - 1
      const q = p / 4
      const m = p % 4
      if (n === '0') {
        zeroCount++
      } else {
        if (zeroCount > 0) {
          chineseStr += cnNums[0]
        }
        // 归零
        zeroCount = 0
        // alert(cnNums[parseInt(n)])
        chineseStr += cnNums[parseInt(n)] + cnIntRadice[m]
      }
      if (m === 0 && zeroCount < 4) {
        chineseStr += cnIntUnits[q]
      }
    }
    chineseStr += cnIntLast
  }
  // 小数部分
  if (decimalNum !== '') {
    const decLen = decimalNum.length
    for (let i = 0; i < decLen; i++) {
      const n = decimalNum.substr(i, 1)
      if (n !== '0') {
        chineseStr += cnNums[Number(n)] + cnDecUnits[i]
      }
    }
  }
  if (chineseStr === '') {
    chineseStr += cnNums[0] + cnIntLast + cnInteger
  } else if (decimalNum === '') {
    chineseStr += cnInteger
  }
  return chineseStr
}

export function TreeArrar(data) {
         const hasChild = data.children && data.children.length > 0;
         return {
           label: data.categoryName,
           value: data.id,
           children: hasChild ? data.children.map(i => TreeArrar(i)) : null
         };
       }


export const toolbarOptions = [
         ["bold", "italic", "underline", "strike"], //加粗，斜体，下划线，删除线
         ["blockquote", "code-block"], //引用，代码块
         [{ header: 1 }, { header: 2 }], // 标题，键值对的形式；1、2表示字体大小
         [{ list: "ordered" }, { list: "bullet" }], //列表
         [{ script: "sub" }, { script: "super" }], // 上下标
         [{ indent: "-1" }, { indent: "+1" }], // 缩进
         [{ direction: "rtl" }], // 文本方向
         [{ size: ["small", false, "large", "huge"] }], // 字体大小
         [{ header: [1, 2, 3, 4, 5, 6, false] }], //几级标题
         [{ color: [] }, { background: [] }], // 字体颜色，字体背景颜色
         [{ font: [] }], //字体
         [{ align: [] }], //对齐方式
         ["image", "link"],
         ["clean"] //清除字体样式
       ];

export const handlers = {
         image: function image() {
           let self = this;
           var fileInput = this.container.querySelector(
             "input.ql-image[type=file]"
           );
           if (fileInput === null) {
             fileInput = document.createElement("input");
             fileInput.setAttribute("type", "file");
             fileInput.setAttribute(
               "accept",
               "image/png, image/gif, image/jpeg",
               "image/jpg"
             );
             fileInput.classList.add("ql-image");
             fileInput.addEventListener("change", async function() {
               let file = fileInput.files[0];
               if (!/image\/\w+/.test(file.type)) {
                 Message({
                   message: "格式错误，请上传png、gif、jpg格式",
                   type: "info",
                   duration: 5 * 1000
                 });
                 return false;
               }
               let form = new FormData();
               form.append("resType", fileInput.files[0]);
               const { code, data } = await uploads("aboutEditorImg", form);

               let length = self.quill.getSelection(true).index;
               self.quill.insertEmbed(
                 length,
                 "image",
                 `${process.env.VUE_APP_FILE}${data}`
               );
               self.quill.setSelection(length + 1);
             });
             this.container.appendChild(fileInput);
           }
           fileInput.click();
         }
       };
  //  link: function (value) {
  //     if (value) {
  //       let href = prompt("请输入链接地址");
  //       if (href) {
  //         if (!href.startsWith("http://") && !href.startsWith("https://")) {
  //           href = "https://" + href; // 默认添加 https://
  //         }
  //         this.quill.format("link", href);
  //       }
  //     } else {
  //       this.quill.format("link", false); // 移除链接
  //     }
  //   }


/*

import Vue from 'vue';
import VeeValidate,{ Validator } from 'vee-validate';
import message from './message';

Vue.use(VeeValidate)
Validator.localize('ch', message);

//验证规则
Validator.extend('mobile',{ //手机号码验证
    getMessage: '请输入正确的手机号码！',
    validate: value => {
        return  /^(\+86)?1[3456789]\d{9}$/.test(value);
    }
})

Validator.extend('custName',{ // 客户名称
    getMessage: '请输入正确的客户名称！',
    validate: value => {
        return /^[\u4E00-\u9FA5A-Za-z()（）]+$/.test(value);
    }
})

Validator.extend('email',{ //邮箱地址验证
    getMessage: '请输入正确的邮箱地址！',
    validate: value => {
        return /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/.test(value);
    }
})

Validator.extend('cardId',{ //身份证号码验证
    getMessage: '请输入正确的身份证号码！',
    validate: value => {
        return /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(value);
    }
})

Validator.extend('isQQ',{ //QQ号码验证
    getMessage: '请输入正确的QQ号码！',
    validate: value => {
        return /^[1-9][0-9]{4,}$/.test(value);
    }
})

Validator.extend('isWX',{ //微信号码验证
    getMessage: '请输入正确的微信号码！',
    validate: value => {
        return /^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/.test(value);
    }
})

Validator.extend('isPhone',{ //电话号码验证
    getMessage: '请输入正确的电话号码！',
    validate: value => {
        return /^(\+86)?1[3456789]\d{9}$/.test(value);
    }
})

Validator.extend('isfax',{ //传真号码验证
    getMessage: '请输入正确的传真号码！',
    validate: value => {
        return /^(\d{3,4}-)?\d{7,8}$/.test(value);
    }
})

Validator.extend('isHomeNum',{ //家庭电话号码
    getMessage: '请输入正确的家庭电话号码！',
    validate: value => {
        let reg = /^(\d{3,4}-)\d{7,8}$/;
        let reg1 = /^(1[3456789]\d{9})$/;
        let reg2 = /^(\+86)?[0-9]{1,11}$/;
        return reg.test(value) || reg1.test(value) || reg2.test(value);
    }
})

Validator.extend('isTax',{ //传真号码验证
    getMessage: '请输入正确的税务号！',
    validate: value => {
        let reg = /^[A-Z0-9]{15}$/;
        let reg1 = /^[A-Z0-9]{18}$/;
        return reg.test(value) || reg1.test(value)
    }
})

Validator.extend('isCard',{ //通用证件号码验证
    getMessage: '请输入正确的号码！',
    validate: value => {
        let reg = /^[\u4e00-\u9fa5]+$/;
        return !reg.test(value);
    }
})

*/

/*
// 身份证15位转18位
checkCardID (cardID) {
    let v = new Array();
    let vs = "10X98765432";
    let cardObj = {
        code:'',
        val: ''
    }
    v.push(2, 4, 8, 5, 10, 9, 7, 3, 6, 1, 2, 4, 8, 5, 10, 9, 7);
    if (cardID.length != 15) {
        cardObj.code = '0';
        cardObj.val = "请输入15位身份证号码！";
        return cardObj;
    }
    let reg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/;
    if (reg.test(cardID) === false) {
        cardObj.code = '0';
        cardObj.val = "请输入正确的身份证信息"
        return cardObj;
    }
    //将15位的号码转换位17位
    let cardIDcardID17 = cardID.substring(0, 6) + "19" + cardID.substring(6);
    let N = 0;
    let R = -1;
    let T = '0';//储存最后一个数字
    let j = 0;
    //计数出第18位数字
    for (let i = 16; i >= 0; i--) {
        N += parseInt(cardIDcardID17.substring(i, i + 1)) * v[j];
        j++;
    }
    R = N % 11;
    T = vs.charAt(R);
    cardObj.code = '1';
    cardObj.val = cardIDcardID17 + T;
    return cardObj;
},
//判断输入的月份是否正确
checkMonth(month) {
    if (month < 1 || month > 12) {
        return false;
    }
    return true;
},
 //检查你输入的天数是否正确
 //yean为年
 //month为月
 //day为日
checkDay (year, month, day) {
    let Mday = 0;
    if (day < 1 || day > 31) {
        return false;
    }
    if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
        Mday = 31;
    }
    if (month == 4 || month == 6 || month == 9 || month == 11) {
        Mday = 30;
    }
    if (month == 2) {
        Mday = isLeapYear(year);
    }
    if (day > Mday) {
        return false;
    }
    return true;
},
//判断你输入的年是否位闰年
isLeapYear(year) {
    return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0) ? 29 : 28;
},

// 身份证判断
isCardId(card) {
    let reg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
    return reg.test(card);
},

//验证是否是中文
 
var pattern = new RegExp("[\u4E00-\u9FA5]+");
var str = "中文字符"
if(pattern.test(str)){
    alert('该字符串是中文');
}
 
//验证是否是英文
 
var pattern2 = new RegExp("[A-Za-z]+");
var str2 = "abcdefsgaaweg"
if(pattern2.test(str2)){
    alert('该字符串是英文');
}
 
//验证是否是数字
var pattern3 = new RegExp("[0-9]+");
var str3 = "234234"
if(pattern3.test(str3)){
    alert('该字符串是数字');
}


// 护照判断
isPassPort(card) {
    let reg = /^([a-zA-z]|[0-9]){6,64}$/;
    return reg.test(card);
},

// 港澳台通行证
isPassCard(card) {
    let reg = /^[HMhm]{1}([0-9]{10}|[0-9]{8})$/;
    let reg1 = /^[0-9]{8}$/;
    let reg2 = /^[0-9]{10}$/;
    return reg.test(card) || reg1.test(card) || reg2.test(card);
},

// 军人证件
isSoldier (card) {
    // 样本： 军字第2001988号, 士字第P011816X号
    let reg = /^[\u4E00-\u9FA5](字第)([0-9a-zA-Z]{4,8})(号?)$/;
    return reg.test(card) 
},

// 组织机构代码证
isOrg (card) {
    let reg = /^[A-Za-z0-9]{9}$/;
    return reg.test(card)
},

// 工商登记证
isBusiness (card) {
    let reg = /^([A-Za-z0-9]{15}|[A-Za-z0-9]{18})$/;
    return reg.test(card)
},

// 税务登记证
isTaxAdministration (card) {
    let reg = /^([A-Z0-9]{15}|[A-Z0-9]{17}|[A-Z0-9]{20})$/;
    return reg.test(card)
},

// 事业单位法人证
isInstitution (card) {
    let reg = /^12[\d\w\W]{16}$/;
    return reg.test(card)
},

// 社会团体法人登记证
isSocialOrganization (card) {
    let reg = /^51[\d\w\W]{16}$/;
    return reg.test(card)
},

// 18为证件号码校验
isEighteen (card){
    let reg = /^[A-Za-z0-9]{18}$/;
    return reg.test(card)
},

// 外国人永久居留居住证
isForeign(card) {
    let reg = /^[A-Za-z0-9]{15}$/;
    return reg.test(card)
},

// 户口本校验
isAccountCard(card) {
    // 户口本
    // 规则： 15位数字, 18位数字, 17位数字 + X
    // 样本： 441421999707223115
    var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
    return reg.test(card)
},

// 统一社会信用代码证
isSocialCredit (card) {
    let reg = /^[A-Za-z0-9]{18}$/;
    return reg.test(card)
},


//外国驻华新闻机构证 21  证件子类型
isCheckCard1 (card){
    let reg = /^21[A-Za-z0-9]{16}$/;
    return reg.test(card)
},
isCheckCard789 (card){
    let reg = /^21[A-Za-z0-9]{16}$/;
    return reg.test(card)
},
//宗教活动场所登记证 71
isCheckCard2 (card){
    let reg = /^71[A-Za-z0-9]{16}$/;
    return reg.test(card)
},
//民办非企业单位登记证 52
isCheckCard3 (card){
    let reg = /^52[A-Za-z0-9]{16}$/;
    return reg.test(card)
},
//基金会法人登记证 53
isCheckCard4 (card){
    let reg = /^53[A-Za-z0-9]{16}$/;
    return reg.test(card)
},
//工会法人资格证书 8
isCheckCard5 (card){
    let reg = /^8[A-Za-z0-9]{17}$/;
    return reg.test(card)
},
//律师事务所执业许可证 3
isCheckCard6 (card){
    let reg = /^3[A-Za-z0-9]{17}$/;
    return reg.test(card)
},
//外国律师事务所驻华代表处执业许可证 3
isCheckCard7 (card){
    let reg = /^3[A-Za-z0-9]{17}$/;
    return reg.test(card)
},
//基层群众性自治组织特别法人统一社会信用代码证书 55
isCheckCard8 (card){
    let reg = /^55[A-Za-z0-9]{16}$/;
    return reg.test(card)
},
//上海市农村集体经济组织登记证书 N
isCheckCard9 (card){
    let reg = /^N[A-Za-z0-9]{17}$/;
    return reg.test(card)
},
//境外非政府组织代表机构登记证书 G
isCheckCard10 (card){
    let reg = /^G[A-Za-z0-9]{17}$/;
    return reg.test(card)
}
*/

